<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!-- <body>
    <h2>
        <a id="aHref" href="https://www.electronjs.org/">electron官网</a>
    </h2>
    <h2>嵌入页面</h2>
    <button id="btn">打开子窗口</button>
    <script src="./render/index.js"></script>
</body> -->

<!-- 父子窗口交流 -->
<!-- <body>

    <button id="btn">打开子窗口 </button>
    <div id="message"></div>
</body>
<script>
    const btn = document.getElementById('btn');
    btn.onclick = ()=>{
        window.open('son.html')
    }
    const message = document.getElementById('message')
    window.addEventListener('message',msg => {
        message.innerHTML = msg.data
    })
</script> -->

<!-- <body>
    <button id="btn">打开文件</button>
</body>
<script>
    const btn=document.getElementById('btn');
    const {dialog}=require('electron').remote;
    btn.onclick=function(){
        dialog.showOpenDialog({
            title:'electron'
        })
    }
</script> -->

<!-- <body>
    <button id="btn">打开文件</button>
</body>
<script>
    const btn=document.getElementById('btn');
    const {dialog}=require('electron').remote;
    btn.onclick=function(){
        dialog.showOpenDialog({
            title:'electron',
            defaultPath:'sunny.png'
        })
    }
</script> -->


<!-- <body>
    <button id="btn">打开文件</button>
</body>
<script>
    const btn=document.getElementById('btn');
    const {dialog}=require('electron').remote;
    btn.onclick=function(){
        dialog.showOpenDialog({
            title:'electron',
            defaultPath:'选择的默认路径',
            // 文件选择过滤
            filters:[
                {
                    name:'jpg',
                    extensions:['jpg']
                }
            ],
            buttonLabel:'确认与否',
            // 对话框使用的功能，允许选择文件、允许多选
            properties:['openFile', 'multiSelections']
        }).then(res=>{
            console.log(res)
        }).catch(err=>{
            console.log(err)
        })
    }
</script> -->

<!-- <body>
    <button id="btn">保存对话框</button>
</body>
<script>
    const btn=document.getElementById('btn');
    const fs=require('fs')
    const {dialog}=require('electron').remote;
    btn.onclick=function(){
        dialog.showSaveDialog({
            title:'electron'
        }).then(res=>{
            console.log(res)
            fs.writeFileSync(res.filePath,'hello')
        }).catch(err=>{
            console.log(err)
        })
    }
</script> -->

<!-- <body>
    <button id="btn">消息对话框</button>
</body>
<script>
    const btn=document.getElementById('btn');
    const {dialog}=require('electron').remote;
    btn.onclick = () => {
        dialog.showMessageBox({
            type: "error",
            title: "错误",
            message: "这是错误警告",
            buttons: ["确定", "忽视","退出"],
        }).then(res => {
            console.log(res)
            });
    };
</script> -->

<!-- <body>
    <h2>断网提醒</h2>
</body>
<script>
  //需要自己手动连接或断开网络
    window.addEventListener('online',()=>{
        alert('网络正常，放心使用')
    })
    window.addEventListener('offline',()=>{
        alert('网络异常，请检查网络是否连接')
    })
</script> -->

<!-- <body>
    <button id="btn">通知消息</button>
</body>
<script>
    const btn = document.getElementById('btn');
    const option = {
        title: '新消息提醒',
        body: '你有新的消息需要阅读'
    }
    btn.onclick = ()=>{
        new window.Notification(option.title,option)
    } 
</script> -->

<!-- <h2>全局注册快捷键</h2> -->

<body>
    <h3>剪贴板的操作</h3><br/>
    <div>
        复制信息: <span id="message">你好,sunny!</span
        ><button id="btn">点击复制</button>
    </div>
    <h3 id="txt"></h3>
</body>
<script>
    const btn = document.getElementById('btn');
    const txt=document.getElementById('txt')
    const message = document.getElementById('message');
    const { clipboard } = require('electron');
    btn.onclick = ()=>{
        //文字复制粘贴
        clipboard.writeText(message.innerHTML,'mes');
        alert('成功复制!')
        txt.innerText=clipboard.readText('mes')
        //html添加
        // clipboard.writeHTML('<h1>阳光正暖</h1>')
        // txt.innerHTML=clipboard.readHTML()
    } 
</script>
</html>